package com.cyzy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cyzy.domain.dto.ResponseData;
import com.cyzy.domain.query.WareHouseQuery;
import com.cyzy.domain.vo.TLog;
import com.cyzy.domain.vo.TWarehouseVo;
import com.cyzy.mapper.WarehouseMapper;
import com.cyzy.service.WareHosueService;
import lombok.experimental.Accessors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WareHouseImpl implements WareHosueService {
    @Autowired
    private WarehouseMapper warehouseMapper;
//    查询该用户的仓库
    @Override
    public ResponseData warehousedata(WareHouseQuery wareHouseQuery) {
        System.out.println("111111111111");
        // 创建分页对象
        Page<TWarehouseVo> page = new Page<>(wareHouseQuery.getCurrentPage(), wareHouseQuery.getSize());
        // 使用 QueryWrapper 构造查询条件
        QueryWrapper<TWarehouseVo> queryWrapper = new QueryWrapper<>();
        if (wareHouseQuery.getUserId() != 0) {
            queryWrapper.eq("user_id", wareHouseQuery.getUserId());
        }
        // 查询分页数据
        Page<TWarehouseVo> plantPage = warehouseMapper.selectPage(page, queryWrapper);
        // 获取分页数据列表
        List<TWarehouseVo> data = plantPage.getRecords();

        // 将分页数据封装到 ResponseData 中
        ResponseData responseData = new ResponseData();
        responseData.setData(data);
        responseData.setCode(200);
        return responseData;
    }
}
